#include <iostream>
#include <vector>
#include <stack>

using namespace std;

#define PII pair<int, int>

const int MAXN = 1e6 + 10;

int sum;
PII present;
stack<int> s, scorenow;
vector<int> in;

void dfs(int layer, int maxn){
    if(layer = maxn) if(scorenow.top() > sum) sum = scorenow.top();
    else{
        if(in[layer] == present.first){
            scorenow.push(scorenow.top() + in[layer]);
            dfs(layer + 1, maxn);
            scorenow.pop();
        }
        else if(in[layer] == present.second){
            scorenow.push(scorenow.top() + in[layer]);
            dfs(layer + 1, maxn);
            scorenow.pop();
        }
        else{
            present.first = in[layer];
            s.push(in[layer]);
            dfs(layer + 1, maxn);
            s.pop();
            present.first = s.top();
            present.second = in[layer];
            s.push(in[layer]);
            dfs(layer + 1, maxn);
            s.pop();
            present.second = s.top(); 
        }
    }
}

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T, n, input;
    cin>>T;
    sum = 0;
    for(int i = 0; i < T; i++){
        cin>>n;
        in.clear();
        for(int j = 0; i < n; j++){
            cin>>input;
            in.push_back(input);
        }
        dfs(0, n);
        cout<<sum<<endl;
    }
    return 0;
}